package com.burstly.lib.conveniencelayer;

import android.app.Activity;
import android.support.v4.app.Fragment;
import com.burstly.lib.conveniencelayer.events.AdCacheEvent;
import com.burstly.lib.conveniencelayer.events.AdDismissFullscreenEvent;
import com.burstly.lib.conveniencelayer.events.AdFailEvent;
import com.burstly.lib.conveniencelayer.events.AdHideEvent;
import com.burstly.lib.ui.BurstlyView;
import java.util.Iterator;
import java.util.List;

public class BurstlyInterstitial extends BurstlyBaseAd
  implements ICacheable
{
  private boolean mAutoCached;
  private boolean mShowTriggered;

  public BurstlyInterstitial(Activity paramActivity, String paramString1, String paramString2, boolean paramBoolean)
  {
    super(paramActivity, BurstlyAdSize.INTERSTITIAL);
    this.mAutoCached = paramBoolean;
    initNewBurstlyInterstitial(paramActivity, paramString1, paramString2);
  }

  public BurstlyInterstitial(Fragment paramFragment, String paramString1, String paramString2, boolean paramBoolean)
  {
    super(paramFragment, BurstlyAdSize.INTERSTITIAL);
    this.mAutoCached = paramBoolean;
    initNewBurstlyInterstitial(paramFragment.getActivity(), paramString1, paramString2);
  }

  public void cacheAd()
  {
    if (this.mAutoCached)
      throw new RuntimeException("Automatic caching enabled for " + getName() + ". Do not attempt to manually cache an ad also");
    super.baseCacheAd();
  }

  public boolean hasCachedAd()
  {
    return super.baseHasCachedAd();
  }

  void initNewBurstlyInterstitial(Activity paramActivity, String paramString1, String paramString2)
  {
    BurstlyView localBurstlyView = new BurstlyView(paramActivity);
    localBurstlyView.setPublisherId(Burstly.getAppID());
    localBurstlyView.setZoneId(paramString1);
    localBurstlyView.setBurstlyViewId(paramString2);
    setBurstlyView(localBurstlyView);
    if (this.mAutoCached)
      super.baseCacheAd();
  }

  public boolean isCachingAd()
  {
    return super.baseIsCachingAd();
  }

  protected void onCache(AdCacheEvent paramAdCacheEvent)
  {
    super.onCache(paramAdCacheEvent);
    if (this.mShowTriggered)
    {
      this.mShowTriggered = false;
      showAd();
    }
  }

  protected void onDismissFullscreen(AdDismissFullscreenEvent paramAdDismissFullscreenEvent)
  {
    super.onDismissFullscreen(paramAdDismissFullscreenEvent);
    if ((this.mAutoCached) && (!hasCachedAd()))
      super.baseCacheAd();
    onHide(new AdHideEvent(false, this.mLastShow));
  }

  protected void onFail(AdFailEvent paramAdFailEvent)
  {
    this.mCachingState = BurstlyBaseAd.CachingState.Idle;
    this.mShowTriggered = false;
    if ((!this.mAutoCached) || (!paramAdFailEvent.wasFailureResultOfCachingAttempt()))
    {
      Iterator localIterator = this.mListeners.iterator();
      while (localIterator.hasNext())
        ((IBurstlyListener)localIterator.next()).onFail(this, paramAdFailEvent);
    }
  }

  protected void resumed()
  {
    super.resumed();
    this.mShowTriggered = false;
    if ((this.mAutoCached) && (!hasCachedAd()))
    {
      this.mCachingState = BurstlyBaseAd.CachingState.Retrieving;
      super.baseCacheAd();
    }
  }

  public void showAd()
  {
    if (this.mAutoCached)
    {
      if (this.mCachingState == BurstlyBaseAd.CachingState.Retrieving)
        this.mShowTriggered = true;
      while (this.mCachingState != BurstlyBaseAd.CachingState.Retrieved)
        return;
      super.showAd();
      return;
    }
    super.showAd();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.conveniencelayer.BurstlyInterstitial
 * JD-Core Version:    0.6.2
 */